package com.ziroom.finance.rabbitmq.common.util;


import com.ziroom.finance.rabbitmq.common.enums.TextTemplateEnum;

import java.util.Map;

/**
 * 短信模板类
 * Date: 2016/11/2
 * Time: 15:15
 *
 * @author qiuy19@ziroom.com
 */
public class TextTemplateUtil {
    private final static String ERROR_CODE_MSG_CONFIG_PATH = "/sms-template.properties";

    /**
     * 根据枚举获取模板
     */
    private static String getTemplate(TextTemplateEnum temp) {
        return PropertiesUtil.getPropValAsString("api.sms." + temp.index,
            ERROR_CODE_MSG_CONFIG_PATH);
    }


    /**
     * 根据模板和键值对生产
     * @param template 模板
     * @param keyValues 键值对
     * @return
     */
    public static String generateText(TextTemplateEnum template, Map<String, String> keyValues){
        String text = getTemplate(template);
        for (Map.Entry<String, String> e :keyValues.entrySet()){
            text = text.replace("{"+e.getKey()+"}", e.getValue());
        }
        return text;
    }


}
